﻿using System;
using System.Collections;

namespace SortedLists
{
    class Program
    {
        static void Main(string[] args)
        {
            //有序列表SortedList
            SortedList sortedList = new SortedList();
            sortedList.Add(1, "篮球");
            sortedList.Add(2, "足球");
            sortedList.Add(3, "羽毛球");
            sortedList.Add(4, "乒乓球");
            sortedList.Add(5, "排球");
            sortedList.Add(6, "***");
            Console.WriteLine("请输入球类编号");
            int id = int.Parse(Console.ReadLine());
            bool num = sortedList.ContainsKey(id);
            if (num)
            {
                string name = sortedList[id].ToString();
                Console.WriteLine("您查找的球类名称为：" + name);
            }
            else
            {
                Console.WriteLine("您查找的球类编号不存在！");
            }

                sortedList.Remove(6);//移除错误

            Console.WriteLine("所有球类的名称如下：");
            foreach (DictionaryEntry item in sortedList)
            {
                int key = (int)item.Key;
                string value = item.Value.ToString();
                Console.WriteLine("球类编号：{0},球类：{1}",key,value);
            }
        }
    }
}
